package com.ssm.gbq.service.impl;

import com.ssm.gbq.dao.DoctorDao;
import com.ssm.gbq.model.Doctor;
import com.ssm.gbq.service.DoctorService;
import gbq.ssm.utils.BusinessException;
import gbq.ssm.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoctorServiceImpl implements DoctorService{
    
    @Autowired
    private DoctorDao doctorDao;

    public PageBounds<Doctor> openDoctorTable(String nameOrPhone, int currentPage, int pageSize)
            throws BusinessException {
        try {
            return doctorDao.openDoctorTable(nameOrPhone,currentPage,pageSize);
        } catch (Exception e) {
            throw new BusinessException("分页查询失败！",e.getMessage());
        }
    }

    public Doctor getDoctorById(Integer id) throws BusinessException {
        try {
            return doctorDao.getDoctorById(id);
        } catch (Exception e) {
            throw new BusinessException("通过id查询失败！",e.getMessage());
        }
    }

    public List<Doctor> searchDoctor(String nameOrPhone) throws BusinessException {
        try {
            return doctorDao.searchDoctor(nameOrPhone);
        } catch (Exception e) {
            throw new BusinessException("通过username获取当前学生信息失败！",e.getMessage());
        }
    }

    public void addDoctor(Doctor doctor) throws BusinessException {
        try {
            doctorDao.addDoctor(doctor);
        }catch (Exception e) {
            throw new BusinessException("添加失败！",e.getMessage());
        }
    }

    public void delDoctorById(List<Integer> ids) throws BusinessException {
        try {
            doctorDao.delDoctorById(ids);
        } catch (Exception e) {
            throw new BusinessException("删除失败！",e.getMessage());
        }
    }

    public void updateDoctor(Doctor doctor) throws BusinessException {
        try {
            doctorDao.updateDoctor(doctor);
        } catch (BusinessException e) {
            throw new BusinessException("修改失败！",e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<Doctor> getDoctorByDepartment(Integer courseId) throws BusinessException {
        return null;
    }

}
